Fixed compiler warnings. Fixed write to unallocated memory (row_ptr), and
authorFederico Mena Quintero <federico@nuclecu.unam.mx>
Mon, 9 Aug 1999 06:09:24 +0000 (06:09 +0000)
committerArturo Espinosa <unammx@src.gnome.org>
Mon, 9 Aug 1999 06:09:24 +0000 (06:09 +0000)
1999-08-09  Federico Mena Quintero  <federico@nuclecu.unam.mx>

* src/io-png.c (image_save): Fixed compiler warnings.  Fixed write
to unallocated memory (row_ptr), and fixed its type as well.  Take
into account the ArtPixbuf's rowstride when assigning the row
pointers.

* src/gdk-pixbuf.c: Fixup includes.

* src/gdk-pixbuf-io.c: Likewise.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-io.c
gdk-pixbuf/gdk-pixbuf.c
gdk-pixbuf/io-gif.c
gdk-pixbuf/io-jpeg.c
gdk-pixbuf/io-png.c
gdk-pixbuf/io-xpm.c

index 34dbf98351f0e1d5c1b4fa4f5f378f3601eac258..90125f1a992ead907ccf60c0affbb94ba4d9f31c 100644 (file)
@@ -1,3 +1,14 @@
+1999-08-09  Federico Mena Quintero  <federico@nuclecu.unam.mx>
+
+       * src/io-png.c (image_save): Fixed compiler warnings.  Fixed write
+       to unallocated memory (row_ptr), and fixed its type as well.  Take
+       into account the ArtPixbuf's rowstride when assigning the row
+       pointers.
+
+       * src/gdk-pixbuf.c: Fixup includes.
+
+       * src/gdk-pixbuf-io.c: Likewise.
+
 Sat Jul 31 19:19:47 CEST 1999
 
        * src/gdk-pixbuf-io.c:
index 7a06da6a309a95102bb4dc84cb8e3a9165a15adb..7b644000eba05dc65c710cf72d0323771f0dbf25 100644 (file)
@@ -4,8 +4,10 @@
  * Author:
  *    Miguel de Icaza (miguel@gnu.org)
  */
+
 #include <config.h>
 #include <stdio.h>
+#include <string.h>
 #include <glib.h>
 #include <gmodule.h>
 #include "gdk-pixbuf.h"
@@ -37,7 +39,7 @@ pixbuf_check_jpeg (unsigned char *buffer, int size)
 
        if (buffer [0] != 0xff || buffer [1] != 0xd8)
                return FALSE;
-       
+
        return TRUE;
 }
 
@@ -47,18 +49,18 @@ pixbuf_check_tiff (unsigned char *buffer, int size)
        if (size < 10)
                return FALSE;
 
-       if (buffer [0] == 'M' && 
-           buffer [1] == 'M' && 
-           buffer [2] == 0   && 
+       if (buffer [0] == 'M' &&
+           buffer [1] == 'M' &&
+           buffer [2] == 0   &&
            buffer [3] == 0x2a)
                return TRUE;
 
-       if (buffer [0] == 'I' && 
-           buffer [1] == 'I' && 
-           buffer [2] == 0x2a && 
+       if (buffer [0] == 'I' &&
+           buffer [1] == 'I' &&
+           buffer [2] == 0x2a &&
            buffer [3] == 0)
                return TRUE;
-       
+
        return FALSE;
 }
 
@@ -67,10 +69,10 @@ pixbuf_check_gif (unsigned char *buffer, int size)
 {
        if (size < 20)
                return FALSE;
-               
+
        if (strncmp (buffer, "GIF8", 4) == 0)
                return TRUE;
-       
+
        return FALSE;
 }
 
@@ -79,10 +81,10 @@ pixbuf_check_xpm (unsigned char *buffer, int size)
 {
        if (size < 20)
                return FALSE;
-       
+
        if (strncmp (buffer, "/* XPM */", 9) == 0)
                return TRUE;
-       
+
        return FALSE;
 }
 
@@ -91,10 +93,10 @@ pixbuf_check_bmp (unsigned char *buffer, int size)
 {
        if (size < 20)
                return FALSE;
-       
+
        if (buffer [0] != 'B' || buffer [1] != 'M')
                return FALSE;
-       
+
        return TRUE;
 }
 
@@ -133,15 +135,6 @@ static struct {
        { NULL, NULL, NULL, NULL, NULL }
 };
 
-static int
-image_file_format (const char *file)
-{
-       FILE *f = fopen (file, "r");
-
-       if (!f)
-               return -1;
-}
-
 static void
 image_handler_load (int idx)
 {
@@ -149,8 +142,8 @@ image_handler_load (int idx)
        char *path;
        GModule *module;
        void *load_sym, *save_sym;
-       
-       module_name = g_strconcat ("pixbuf-", 
+
+       module_name = g_strconcat ("pixbuf-",
                                   file_formats [idx].module_name, NULL);
        path = g_module_build_path (PIXBUF_LIBDIR, module_name);
        g_free (module_name);
@@ -184,7 +177,7 @@ gdk_pixbuf_load_image (const char *file)
        n = fread (&buffer, 1, sizeof (buffer), f);
 
        if (n == 0){
-               fclose (f);             
+               fclose (f);
                return NULL;
        }
 
index c786c1ddf7a1e29ce7ee2bb582833198bf8a67a5..82acf793a5c5a4d7572ae5c6ac32c7d433c1246b 100644 (file)
@@ -5,11 +5,14 @@
  *    Miguel de Icaza (miguel@gnu.org)
  *    Mark Crichton (crichton@gimp.org)
  */
+
 #include <config.h>
 #include <glib.h>
 #include <math.h>
 #include <libart_lgpl/art_misc.h>
-#include <libart_lgpl/art_rgb_affine.h>
+#include <libart_lgpl/art_affine.h>
+#include <libart_lgpl/art_pixbuf.h>
+#include <libart_lgpl/art_rgb_pixbuf_affine.h>
 #include <libart_lgpl/art_alphagamma.h>
 #include "gdk-pixbuf.h"
 
@@ -25,7 +28,7 @@ void
 gdk_pixbuf_ref (GdkPixBuf *pixbuf)
 {
      g_return_if_fail (pixbuf != NULL);
-     
+
      pixbuf->ref_count++;
 }
 
@@ -34,7 +37,7 @@ gdk_pixbuf_unref (GdkPixBuf *pixbuf)
 {
     g_return_if_fail (pixbuf != NULL);
     g_return_if_fail (pixbuf->ref_count == 0);
-    
+
     pixbuf->ref_count--;
     if (pixbuf->ref_count)
        gdk_pixbuf_destroy (pixbuf);
@@ -43,7 +46,6 @@ gdk_pixbuf_unref (GdkPixBuf *pixbuf)
 GdkPixBuf *
 gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
 {
-    GdkPixBuf *spb;
     art_u8 *pixels;
     gint rowstride;
     double affine[6];
@@ -53,8 +55,8 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
     alphagamma = NULL;
 
     affine[1] = affine[2] = affine[4] = affine[5] = 0;
-    
-    
+
+
     affine[0] = w / (double)(pixbuf->art_pixbuf->width);
     affine[3] = h / (double)(pixbuf->art_pixbuf->height);
 
@@ -62,15 +64,15 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
     rowstride = w * 3;
 
     pixels = art_alloc (h * rowstride);
-    art_rgb_pixbuf_affinepixels, 0, 0, w, h, rowstride,
+    art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
                           pixbuf->art_pixbuf,
                           affine, ART_FILTER_NEAREST, alphagamma);
 
     if (pixbuf->art_pixbuf->has_alpha)
       /* should be rgba */
-      art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride); 
-    else 
-      art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride); 
+      art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+    else
+      art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
 
     art_pixbuf_free (pixbuf->art_pixbuf);
     pixbuf->art_pixbuf = art_pixbuf;
@@ -81,7 +83,6 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
 GdkPixBuf *
 gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
 {
-     GdkPixBuf *rotate;
      art_u8 *pixels;
      gint rowstride, w, h;
      gdouble rad;
@@ -126,9 +127,9 @@ gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
                            affine, ART_FILTER_NEAREST, alphagamma);
      if (pixbuf->art_pixbuf->has_alpha)
          /* should be rgba */
-         art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride); 
-     else 
-         art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride); 
+         art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+     else
+         art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
 
      art_pixbuf_free (pixbuf->art_pixbuf);
      pixbuf->art_pixbuf = art_pixbuf;
index 7db7adece6e515087b0408fedde9f9c5c22239b1..926964f39d625c3f962ea2a7f1401649d6c2bf4a 100644 (file)
@@ -181,5 +181,3 @@ GdkPixBuf *image_load(FILE * f)
 }
 
 image_save() {}
-
-
index 564626242d9498ba9782d9a9789a1f909a21f8bb..8e2a830bdde715955ab61f6fdcf3b54f0c6e46fd 100644 (file)
@@ -42,7 +42,7 @@ g_JPEGFatalErrorHandler(j_common_ptr cinfo)
 GdkPixBuf *image_load(FILE *f)
 {
        int w,h,i,j;
-       art_u8 *pixels=NULL, *dptr, *fptr, *pptr;
+       art_u8 *pixels=NULL, *dptr;
        unsigned char *lines[4], /* Used to expand rows, via rec_outbuf_height, from
                                  the header file:
                                  "* Usually rec_outbuf_height will be 1 or 2, at most 4." */
@@ -123,7 +123,7 @@ GdkPixBuf *image_load(FILE *f)
        }
        pixbuf->ref_count = 0;
        pixbuf->unref_func = NULL;
-       
+
        return pixbuf;
 }
 
index 514b13c8e51ca71057a18a1199d414be808784bd..9746ed21c79fb4e16f922abffd12608381ffd00f 100644 (file)
@@ -170,12 +170,12 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
      png_infop info_ptr;
      art_u8 *data;
      gint y, h, w;
-     png_bytep row_ptr;
+     png_bytepp row_ptr;
      png_color_8 sig_bit;
      gint type;
-     
-     g_return_val_if_fail(file != NULL, NULL);
-     g_return_val_if_fail(pixbuf != NULL, NULL);
+
+     g_return_val_if_fail(file != NULL, FALSE);
+     g_return_val_if_fail(pixbuf != NULL, FALSE);
 
      h = pixbuf->art_pixbuf->height;
      w = pixbuf->art_pixbuf->width;
@@ -184,20 +184,20 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
                                       NULL, NULL, NULL);
      if (png_ptr == NULL) {
          fclose(file);
-         return NULL;
+         return FALSE;
      }
 
      info_ptr = png_create_info_struct(png_ptr);
      if (info_ptr == NULL) {
          fclose(file);
          png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
-         return NULL;
+         return FALSE;
      }
 
      if (setjmp(png_ptr->jmpbuf)) {
          fclose(file);
          png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
-         return NULL;
+         return FALSE;
      }
 
      png_init_io(png_ptr, file);
@@ -218,18 +218,24 @@ int image_save(GdkPixBuf *pixbuf, FILE *file)
      png_set_packing(png_ptr);
 
      data = pixbuf->art_pixbuf->pixels;
+     row_ptr = g_new(png_byte *, h);
 
-     for (y = 0; y < h; y++) {
+     for (y = 0; y < h; y++)
+        row_ptr[y] = data + y * pixbuf->art_pixbuf->rowstride;
+#if 0
+     {
          if (pixbuf->art_pixbuf->has_alpha)
               row_ptr[y] = data + (w * y * 4);
          else
               row_ptr[y] = data + (w * y * 3);
      }
+#endif
 
      png_write_image(png_ptr, row_ptr);
+     g_free (row_ptr);
+
      png_write_end(png_ptr, info_ptr);
      png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
 
      return TRUE;
 }
-     
index 98c7532f179f24c6c513042033ba91f32be33bb0..b97fca2f110c3ab79674430dbe3f3647d4b7af64 100644 (file)
@@ -342,7 +342,7 @@ static GdkPixBuf *
        color->transparent = FALSE;
 
        color_name = xpm_extract_color(buffer);
-       
+
        if ((color_name == NULL) || (g_strcasecmp(color_name, "None") == 0)
            || (gdk_color_parse(color_name, &color->color) == FALSE)) {
            color->transparent = TRUE;